import { getCreditsListAsync } from '@/api/credits'
export default {
	namespaced: true,
	state() {
		return {
			// 存放 积分明细的数据
			detailsList: []
		}
	},
	mutations: {
		getDetailsList(state, list) {
			state.detailsList = list.reverse()
		}
	},
	getters: {
		getCreditAmounts(state) {
			return state.detailsList.reduce((sum, item) => {
				return (sum += item.pointChange)
			}, 0)
		}
	},
	actions: {
		// 调用接口获取积分明细列表
		async getCreditsList(context, userId) {
			try {
				const res = await getCreditsListAsync(userId)

				console.log('%c [  ]-57', 'font-size:13px; background:pink; color:#bf2c9f;', res)
				context.commit('getDetailsList', res.data.data)
			} catch (error) {
				console.log('%c [ getCreditsList ]-60', 'font-size:13px; background:pink; color:#bf2c9f;', error)
			}
		}
	}
}
